package com.moxiao.yfjh.module.order.dal.mysql.blindTradeOrder;

import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.mybatis.core.mapper.BaseMapperX;
import com.moxiao.yfjh.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.moxiao.yfjh.module.order.controller.admin.blindTradeOrder.vo.BlindTradeOrderExportReqVO;
import com.moxiao.yfjh.module.order.controller.admin.blindTradeOrder.vo.BlindTradeOrderPageReqVO;
import com.moxiao.yfjh.module.order.dal.dataobject.blindTradeOrder.BlindTradeOrderDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 相亲交易订单 Mapper
 *
 * @author mx
 */
@Mapper
public interface BlindTradeOrderMapper extends BaseMapperX<BlindTradeOrderDO> {

    default PageResult<BlindTradeOrderDO> selectPage(BlindTradeOrderPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BlindTradeOrderDO>()
                .eqIfPresent(BlindTradeOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindTradeOrderDO::getAppId, reqVO.getAppId())
                .eqIfPresent(BlindTradeOrderDO::getTerminal, reqVO.getTerminal())
                .eqIfPresent(BlindTradeOrderDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindTradeOrderDO::getNotifyUrl, reqVO.getNotifyUrl())
                .eqIfPresent(BlindTradeOrderDO::getMobile, reqVO.getMobile())
                .likeIfPresent(BlindTradeOrderDO::getUserName, reqVO.getUserName())
                .eqIfPresent(BlindTradeOrderDO::getUserIp, reqVO.getUserIp())
                .eqIfPresent(BlindTradeOrderDO::getUserRemark, reqVO.getUserRemark())
                .eqIfPresent(BlindTradeOrderDO::getOpenNum, reqVO.getOpenNum())
                .eqIfPresent(BlindTradeOrderDO::getOpenLevel, reqVO.getOpenLevel())
                .eqIfPresent(BlindTradeOrderDO::getOpenContent, reqVO.getOpenContent())
                .eqIfPresent(BlindTradeOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindTradeOrderDO::getProductCount, reqVO.getProductCount())
                .eqIfPresent(BlindTradeOrderDO::getCancelType, reqVO.getCancelType())
                .eqIfPresent(BlindTradeOrderDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BlindTradeOrderDO::getBrokerageUserId, reqVO.getBrokerageUserId())
                .eqIfPresent(BlindTradeOrderDO::getPayOrderId, reqVO.getPayOrderId())
                .eqIfPresent(BlindTradeOrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(BlindTradeOrderDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(BlindTradeOrderDO::getPayChannelCode, reqVO.getPayChannelCode())
                .betweenIfPresent(BlindTradeOrderDO::getFinishTime, reqVO.getFinishTime())
                .betweenIfPresent(BlindTradeOrderDO::getCancelTime, reqVO.getCancelTime())
                .eqIfPresent(BlindTradeOrderDO::getTotalPrice, reqVO.getTotalPrice())
                .eqIfPresent(BlindTradeOrderDO::getPayPrice, reqVO.getPayPrice())
                .eqIfPresent(BlindTradeOrderDO::getRefundPrice, reqVO.getRefundPrice())
                .betweenIfPresent(BlindTradeOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlindTradeOrderDO::getId));
    }

    default List<BlindTradeOrderDO> selectList(BlindTradeOrderExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BlindTradeOrderDO>()
                .eqIfPresent(BlindTradeOrderDO::getNo, reqVO.getNo())
                .eqIfPresent(BlindTradeOrderDO::getAppId, reqVO.getAppId())
                .eqIfPresent(BlindTradeOrderDO::getTerminal, reqVO.getTerminal())
                .eqIfPresent(BlindTradeOrderDO::getUserId, reqVO.getUserId())
                .eqIfPresent(BlindTradeOrderDO::getNotifyUrl, reqVO.getNotifyUrl())
                .eqIfPresent(BlindTradeOrderDO::getMobile, reqVO.getMobile())
                .likeIfPresent(BlindTradeOrderDO::getUserName, reqVO.getUserName())
                .eqIfPresent(BlindTradeOrderDO::getUserIp, reqVO.getUserIp())
                .eqIfPresent(BlindTradeOrderDO::getUserRemark, reqVO.getUserRemark())
                .eqIfPresent(BlindTradeOrderDO::getOpenNum, reqVO.getOpenNum())
                .eqIfPresent(BlindTradeOrderDO::getOpenLevel, reqVO.getOpenLevel())
                .eqIfPresent(BlindTradeOrderDO::getOpenContent, reqVO.getOpenContent())
                .eqIfPresent(BlindTradeOrderDO::getStatus, reqVO.getStatus())
                .eqIfPresent(BlindTradeOrderDO::getProductCount, reqVO.getProductCount())
                .eqIfPresent(BlindTradeOrderDO::getCancelType, reqVO.getCancelType())
                .eqIfPresent(BlindTradeOrderDO::getRemark, reqVO.getRemark())
                .eqIfPresent(BlindTradeOrderDO::getBrokerageUserId, reqVO.getBrokerageUserId())
                .eqIfPresent(BlindTradeOrderDO::getPayOrderId, reqVO.getPayOrderId())
                .eqIfPresent(BlindTradeOrderDO::getPayStatus, reqVO.getPayStatus())
                .betweenIfPresent(BlindTradeOrderDO::getPayTime, reqVO.getPayTime())
                .eqIfPresent(BlindTradeOrderDO::getPayChannelCode, reqVO.getPayChannelCode())
                .betweenIfPresent(BlindTradeOrderDO::getFinishTime, reqVO.getFinishTime())
                .betweenIfPresent(BlindTradeOrderDO::getCancelTime, reqVO.getCancelTime())
                .eqIfPresent(BlindTradeOrderDO::getTotalPrice, reqVO.getTotalPrice())
                .eqIfPresent(BlindTradeOrderDO::getPayPrice, reqVO.getPayPrice())
                .eqIfPresent(BlindTradeOrderDO::getRefundPrice, reqVO.getRefundPrice())
                .betweenIfPresent(BlindTradeOrderDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(BlindTradeOrderDO::getId));
    }

    @Select("select count(*) num from blind_trade_order where no = #{orderNo}")
    Integer getMemberUserNo(@Param("orderNo") String orderNo);

    /**
     * 红娘商品购买销量
     *
     * @param productId
     * @return
     */

    @Select("select IFNULL(COUNT(order_id),0)  num from blind_trade_order where order_type = 4 and pay_status = 1 and order_id = #{productId}")
    Integer getMakerSalesVolume(@Param("productId") Long productId);
}
